<template>
  <div style="padding:200px 5%;">
    <el-form ref="elForm" :model="formData" :rules="rules" size="medium" label-width="100px">
      <el-form-item label="车牌号" prop="licenseNumber">
        <el-input v-model="formData.licenseNumber" placeholder="请输入车牌号" show-word-limit clearable
                  prefix-icon='el-icon-mobile' :style="{width: '100%'}"></el-input>
      </el-form-item>
      <el-form-item size="large">
        <el-button type="primary" @click="submitForm">提交</el-button>
        <el-button @click="back">返回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { addCars } from "@/api/modules/merchat/coupon/couponCars";
export default {
  components: {},
  props: [],
  data() {
    return {
      formData: {
        licenseNumber: '',
        coid: null,
      },
      rules: {
        licenseNumber: [{
          required: true,
          message: '请输入车牌号',
          trigger: 'blur'
        }, {
          pattern: /^(京|津|沪|渝|冀|豫|云|辽|黑|湘|皖|鲁|新|苏|浙|赣|鄂|桂|甘|晋|蒙|陕|吉|闽|贵|粤|青|藏|川|宁|琼)[A-Z]{1}[A-Z0-9]{4}[A-Z0-9挂学警港澳试超使领北南军海空外]{1}$/,
          message: '格式错误',
          trigger: 'blur'
        }],
      },
    }
  },
  computed: {},
  watch: {},
  created() {
    this.formData.coid = this.$route.params.id;
  },
  mounted() {},
  methods: {
    submitForm() {
      this.$refs['elForm'].validate(valid => {
        if (!valid) return
        // TODO 提交表单
        addCars(this.formData).then(response=>{
          this.$modal.msgSuccess(response.msg);
          this.back();
        })
      })
    },
    back() {
      this.$store.dispatch('tagsView/delAllViews',this.$router);
      this.$router.push({path:"/merchant/coupon"});
    },
  }
}

</script>
<style>
</style>

